package cn.com.czpb.client.module.news.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.com.czpb.client.R;
import cn.com.czpb.client.model.news.FuWuItemBean;

/**
 * Created by Administrator on 2018/2/24.
 */

public class FuWuMainItemAdapter extends BaseAdapter {
    private List<FuWuItemBean> list;
    private LayoutInflater inflater;
    private Context context;
    public FuWuMainItemAdapter(List<FuWuItemBean> list, Context context) {
        super();
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null)
        {
            convertView = inflater.inflate(R.layout.item_fuwu_main_item, null);
            viewHolder = new ViewHolder();
            viewHolder.title = convertView.findViewById(R.id.fuwu_item_tv);
            viewHolder.image = convertView.findViewById(R.id.fuwu_item_img);
            convertView.setTag(viewHolder);
        } else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.title.setText(list.get(position).getName());
        Glide.with(context).load(list.get(position).getPic()).into(viewHolder.image);
        return convertView;
    }
    class ViewHolder
    {
        public TextView title;
        public ImageView image;
    }
}
